<template>
  <div class="page" style="">
    <div class="print_title">{{ formData.purchaseBill&&formData.purchaseBill.substring(0,2) == 'ZF'?'作废定标结果确认单':'定标结果确认详情' }} · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.purchaseBill }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposer_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.departId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <template v-if="formData.purchaseBill&&formData.purchaseBill.substring(0,2) == 'ZF'">
        <a-divider>作废信息</a-divider>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >单据名称:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.purchaseBillId_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row>
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >申请人:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationProposer_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>

        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >申请部门:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationDepartId_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >申请时间:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationCreateTime }}</p>
            </a-col>
          </a-row>
        </a-col>
      </template>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >工期(供货期):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.supplyTime }}</p>
          </a-col>
        </a-row>
      </a-col> -->
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >开标时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.calibrationTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >预算价(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.budget }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >中标总价(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.totalBidPrice }}</p>
          </a-col>
        </a-row>
      </a-col>
      <!-- <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >开票方式:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invoiceManner }}</p>
          </a-col>
        </a-row>
      </a-col> -->
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >所属团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.teamId_dictText?formData.teamId_dictText:formData.teamId }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col>
            <p style="margin-bottom: 0; white-space: nowrap" >各厂家报价、谈判情况描述及选定该厂家供货的原因(重点描述品牌、价格对比情况、原厂还是代理商等):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.quoteDescription }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col>
            <span style="margin-bottom: 0; white-space: nowrap" >历史采购情况说明(重点描述品牌、价格情况):</span>
            <span style="margin:0 0 0 6px; word-break: break-all;">{{ formData.historyDescription }}</span>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col>
            <span style="margin-bottom: 0; white-space: nowrap" >与采购申请的差异(重点描述规格型号、参数及品牌、数量等更改项目):</span>
            <span style="margin:0 0 0 6px; word-break: break-all;">{{ formData.differenceDescription }}</span>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col>
            <span style="margin-bottom: 0; white-space: nowrap" >申购单位意见(对产品品牌、价格、数量的认可及增减等描述):</span>
            <span style="margin:0 0 0 6px; word-break: break-all;">{{ formData.opinionDescription }}</span>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >备注:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remark }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col style="display: flex;" v-if="formData.purchaseBill&&formData.purchaseBill.substring(0,2) == 'ZF'">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >作废理由:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationReason }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <a-row type="flex" justify="center" style="margin-top: 18px;">
      <a-col>
        <p class="title_table">招标采购申请信息</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="columns"
          :data-source="dataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>
    <a-row type="flex" justify="center" style="margin-top: 18px;">
      <a-col>
        <p class="title_table">中标信息</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="unitColumns"
          :data-source="UnitDataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInforOriginal v-if="formData.bpmStatus !== '1'&&formData.purchaseBill&&formData.purchaseBill.substring(0,2) == 'ZF'" :dataHistorySource="dataOriginalHistorySource"></ProcessInforOriginal>
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import ProcessInforOriginal from '@/components/print/ProcessInforOriginal.vue' // 原单据审批历史流程列表组件
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    },
    OriginalFormData: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor,
    ProcessInforOriginal
  },
  data() {
    return {
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      columns: [
				{
					title: '序号',
					dataIndex: '',
					key: 'rowIndex',
					width: 45,
					align: 'center',
					customRender: function (t, r, index) {
						return parseInt(index) + 1;
					}
				},
				{
					title: '关联招标采购申请',
					align: 'center',
					dataIndex: 'invitationId_dictText'
				},
				{
					title: '项目名称',
					align: 'center',
					dataIndex: 'projectId_dictText'
				},
				{
					title: '团队名称',
					align: 'center',
					dataIndex: 'teamId',
          customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['teamId'], text + '')
              }
            }
				},
				{
					title: '定标意见单',
					align: 'center',
					dataIndex: 'opinionId',
          customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['opinionId'], text + '')
              }
            }
				}
			],
      UnitDataSource: [],
      unitColumns: [
      {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 45,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '中标单位',
            align: 'center',
            dataIndex: 'biddingUnit',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['biddingUnit'], text + '')
              }
            }
          },
          {
            title: '中标价(元)',
            width: 75,
            align: 'center',
            dataIndex: 'bidding'
          },
          {
            title: '付款方式',
            align: 'center',
            dataIndex: 'payType'
          },
          {
            title: '税率(%)',
            align: 'center',
            width: 60,
            dataIndex: 'taxRate'
          },
          {
            title: '发票类型',
            width: 65,
            align: 'center',
            dataIndex: 'invoiceCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['invoiceCategory'], text + '')
              }
            }
          },
          {
            title: '工期(供货期)',
            width: 75,
            align: 'center',
            dataIndex: 'duration'
          },
          {
            title: '是否垫资',
            align: 'center',
            dataIndex: 'isAdvancePayment',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['isAdvancePayment'], text + '')
              }
            }
          },
          // {
          //   title: '价格执行有效期',
          //   align: 'center',
          //   dataIndex: 'validity',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['validity'], text + '')
          //     }
          //   }
          // }
      ],
			dataHistorySource: [], // 流程列表
      dataOriginalHistorySource: [], // 原单据流程列表
			url: {
				list: '/api/erp/purchase/procurement/erpPurchaseCalibrationDetail/allList', // 招标采购申请列表
				unitList: '/api/erp/purchase/procurement/erpPurchaseCalibrationUnit/allList', // 中标单位列表
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
			purchaseFile: [] // 附件
    };
  },
	watch: {
		formData: {
			handler (val) {
				if (val) {
					this.list()
          this.getUnitList()
					this.getHistoryList()
          this.initDictConfig() // 字典值
					if (val.purchaseFile) {
						this.purchaseFile = val.purchaseFile.split(',')
					}
				}
			},
      deep: true,
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		},
    OriginalFormData: {
			handler (val) {
				if (val) {
					this.getOriginalHistoryList()
				}
			},
			immediate: true
		}
	},
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},
    getOriginalHistoryList() {
			var params = { processInstanceId: this.OriginalFormData.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataOriginalHistorySource = res.result.records || res.result
				}
			})
		},
    initDictConfig() {
        // 团队名称
        initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamId', res.result)
          }
        })

        // 中标单位
        initDictOptions('erp_purchase_supplier,enterprise_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'biddingUnit', res.result)
          }
        })
        // 发票类型
        initDictOptions('invoice_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'invoiceCategory', res.result)
          }
        })
        initDictOptions('yes_no').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'isAdvancePayment', res.result)
          }
        })
        //关联定标意见单
        initDictOptions('erp_purchase_calibration_opinion,purchase_bill,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'opinionId', res.result)
          }
        })
      },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
				billId: this.formData.purchaseBill.substring(0,2) == 'ZF'?this.formData.purchaseBillId:this.formData.id 
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},
		getUnitList () {
			if (!this.formData.id) {
				return false
			}
			var params = {
				billId: this.formData.purchaseBill.substring(0,2) == 'ZF'?this.formData.purchaseBillId:this.formData.id 
			}
			getAction(this.url.unitList, params).then(res => {
				if (res.success) {
						this.UnitDataSource = res.result.records || res.result
						this.UnitDataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
  .content{
  font-size: 13px;
}
</style>
